#####################################################################################
#Figure 5a
#####################################################################################

library(foreign)
library(extrafont)
library(readstata13)
loadfonts()
data<-read.dta13("Figure5a_Preds_reshaped.dta")
scale<-data[,1]
LowBound1<-data[,2]
UpBound1<-data[,3]
LowBound2<-data[,4]
UpBound2<-data[,5]
LowBound3<-data[,6]
UpBound3<-data[,7]

x<-1:735

pdf(file="Figure5a.pdf", family="Bookman")
plot(0, 1, type="n", xlim=rev(range(x)), ylim=c(.65, 1), xlab="Days to Next Election", ylab="Probability of Casting Party Vote")
box() 
title(main="Linear Cycle Trend")

polygon(c(scale, rev(scale)), c(LowBound3, rev(UpBound3)), col="gray72", border=NA)

polygon(c(scale, rev(scale)), c(LowBound2, rev(UpBound2)), density=20, angle=45, col="black")

polygon(c(scale, rev(scale)), c(LowBound1, rev(UpBound1)), col="gray35", border=NA)

legend("bottomleft", cex=.98, legend=c('Early in Time Series', ' + Late Vulnerability Dist.', 'Late in Time Series'), fill=c("gray35", NA, "gray72"), density=c(NA, 30, NA), angle=c(NA, 45, NA), border=c(NA, "black", NA))

dev.off()


#########################################################################################################
#Figure 5b
#########################################################################################################

library(foreign)
library(extrafont)
library(readstata13)
loadfonts()
data<-read.dta13("Figure5b_Preds_reshaped.dta")
scale<-data[,1]
LowBound1<-data[,2]
UpBound1<-data[,3]
LowBound2<-data[,4]
UpBound2<-data[,5]
LowBound3<-data[,6]
UpBound3<-data[,7]

x<-1:735

pdf(file="Figure5b.pdf", family="Bookman")
plot(0, 1, type="n", xlim=rev(range(x)), ylim=c(.65, 1), xlab="Days to Next Election", ylab="Probability of Casting Party Vote")
box() 
title(main="Post-1994 Election Indicator")

polygon(c(scale, rev(scale)), c(LowBound3, rev(UpBound3)), col="gray72", border=NA)

polygon(c(scale, rev(scale)), c(LowBound2, rev(UpBound2)), density=20, angle=45, col="black")

polygon(c(scale, rev(scale)), c(LowBound1, rev(UpBound1)), col="gray35", border=NA)

legend("bottomleft", cex=.98, legend=c('Early in Time Series', ' + Late Vulnerability Dist.', 'Late in Time Series'), fill=c("gray35", NA, "gray72"), density=c(NA, 30, NA), angle=c(NA, 45, NA), border=c(NA, "black", NA))

dev.off()
